
const { ccclass, property } = cc._decorator;

@ccclass
export default class Resize extends cc.Component {

    public onResize() {
        let self = this;
        let _visiableRect = cc.visibleRect;
        if (window.orientation === 90 || window.orientation === -90 || (_visiableRect.width > _visiableRect.height) && !cc.sys.isMobile) {
            console.log('Landspace... 适配高');
            self.node.getComponent(cc.Canvas).fitWidth = false;
            self.node.getComponent(cc.Canvas).fitHeight = true;

            cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE);

            self.node.getComponent(cc.Canvas).designResolution = cc.size(1334, 750);

            if ((_visiableRect.width / _visiableRect.height) > 2) {
                console.log('L Iphonex... 适配宽');
                self.node.getComponent(cc.Canvas).fitWidth = true;
                self.node.getComponent(cc.Canvas).fitHeight = false;
            }
        } else {
            console.log('Portrait... 适配宽');
            self.node.getComponent(cc.Canvas).fitWidth = true;
            self.node.getComponent(cc.Canvas).fitHeight = false;

            cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT);

            self.node.getComponent(cc.Canvas).designResolution = cc.size(750, 1334);

            if ((_visiableRect.height / _visiableRect.width) > 2) {
                console.log('P Iphonex... 适配高');
                self.node.getComponent(cc.Canvas).fitWidth = false;
                self.node.getComponent(cc.Canvas).fitHeight = true;
            }
        }


        cc.find("Canvas").getComponent(cc.Widget).updateAlignment();
    }

    onLoad() {
        let self = this;

        if (!cc.sys.isNative) {
            window.addEventListener('orientationchange', self.onResize.bind(self), false);
        }

        cc.view.setResizeCallback(self.onResize.bind(self));

        self.onResize();
    }


}
